package com.icexxx.icemock.mock;

import java.util.Date;

import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;

public class DateMock implements IceMock {

	@Override
	public String mock(Integer minVal, Integer maxVal, Integer minWidth, Integer maxWidth, String enums,
			String key) {
		if (minVal == null) {
			minVal = -365;
		}
		if (maxVal == null) {
			maxVal = 0;
		}
		return mockDate(minVal, maxVal);
	}

	/**
	 * 模拟日期字符串
	 * 
	 * @param start 当前时间向前的偏移量(天),一般是用负数
	 * @param end   当前时间向后的偏移量(天)
	 * @return 模拟的日期字符串
	 */
	public static String mockDate(int start, int end) {
		int startNum = start * 86400;
		int endNum = end * 86400;
		DateTime randomDate = RandomUtil.randomDate(new Date(), DateField.SECOND, startNum, endNum);
		return DateUtil.formatDateTime(randomDate);
	}
}
